#!/usr/bin
# -*- coding: utf-8 -*-

import mod_parameters as params



TCI = params.PARAMS["testConstructorsInputs"]





# ==============================================================================
class Material():
    PARAMS = None
    TYPE = None

    def __init__(self, uId, parameters):
        if TCI:
            self.testInputs(uId, parameters)
        self.uId = uId
        self.params = parameters

    def testInputs(self, uId, parameters):
        if not isinstance(uId, str):
            raise ValueError
        if not isinstance(parameters, dict):
            raise ValueError
        keys = parameters.keys()
        keys.sort()
        requiredKeys = self.PARAMS.keys()
        requiredKeys.sort()
        if not keys == requiredKeys:
            raise ValueError
        for key, typ in self.PARAMS.items():
            if not isinstance(parameters[key], typ):
                raise ValueError

    def __str__(self):
        a = "Material " + self.TYPE + ":\n"
        a += "- user id: " + self.uId + "\n"
        a += "- parameters:"
        for key, val in self.params.items():
            a += "\n- " + key + ": " + str(val)
        return a



# ==============================================================================
class IsotropicElasticMaterial(Material):
    """ Isotropic elastic material
    """
    PARAMS = {"E": float, "nu": float}
    TYPE = "IsotropicElastic"

    def __init__(self, uId, parameters):
        Material.__init__(self, uId, parameters)



# ==============================================================================
if __name__ == "__main__":
    myMaterial = IsotropicElasticMaterial("Aluminium", {"E":70000.0,
                                                        "nu":0.25})
    print myMaterial
